import requests
import os

image_url = "http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"

desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")

image_path = os.path.join(desktop_path, "image.jpg")

try:
    response = requests.get(image_url)
    response.raise_for_status()  # 检查请求是否成功

    with open(image_path, "wb") as f:
        f.write(response.content)

    print("图片已成功下载并保存到桌面：", image_path)

except requests.exceptions.RequestException as e:
    print("下载图片时出错：", e)
except Exception as e:
    print("保存文件时出错：", e)
